<template>
  <div>
    <el-row class="row" :gutter="20">
      <el-col :span="21">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/teacher' }">教师菜单</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/teacher/topic' }">课题管理</el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
      <el-col :span="3">
        <el-button icon="el-icon-edit" round @click="addDialogVisible = true">添加课题</el-button>
        <topic-add :visible.sync="addDialogVisible" />
      </el-col>
    </el-row>
    <el-table class="elTable" :data="topicList" border stripe height="630" v-loading="loading">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="topNo" label="课题编号"></el-table-column>
      <el-table-column prop="topName" label="课题名称" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="topProperty" label="课题性质"></el-table-column>
      <el-table-column prop="topCategory" label="课题类别"></el-table-column>
      <el-table-column prop="topContent" label="课题内容" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="colName" label="学院"></el-table-column>
      <el-table-column prop="topStateDesc" label="课题状态">
        <template slot-scope="scope">
          <span style="color: #ff6767">{{scope.row.topStateDesc}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="gmtCreate" label="发布时间" sortable></el-table-column>
      <el-table-column label="操作" width="200px">
        <template slot-scope="scope">
          <el-button type="primary" plain @click="updateTopic(scope.row)">更新课题</el-button>
        </template>
      </el-table-column>
    </el-table>
    <topic-update :visible.sync="updateDialogVisible" :topicInfo="topic" />
  </div>
</template>

<script>
import TopicAdd from '../topic/TopicAdd'
import TopicUpdate from '../topic/TopicUpdate'

export default {
  name: 'TeacherTopic',
  components: {
    TopicAdd,
    TopicUpdate
  },
  data () {
    return {
      loading: true,
      addDialogVisible: false,
      updateDialogVisible: false,
      topic: {},
      topicList: []
    }
  },
  methods: {
    listTopic () {
      this.$axios.get('api/teacher/topic')
        .then(response => {
          let result = response.data
          if (result.success) {
            this.topicList = result.data
            console.log('topicList', this.topicList)
          } else {
            this.$message.error(result.msg)
          }
          this.loading = false
        })
    },
    updateTopic (topic) {
      this.updateDialogVisible = true
      this.topic = topic
    }
  },
  mounted () {
    this.listTopic()
  }
}
</script>

<style lang="stylus" scoped>
.row {
  margin: 20px;
}

.elTable >>> .cell {
  text-align: center;
}

.elTable {
  text-align: center;
}
</style>
